package cn.lanqiao.common.utile;

import cn.lanqiao.common.entity.Admin;
import cn.lanqiao.common.entity.User;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class Result<T> {
    private String msg ; //返回的文字提示信息
    private T data ;     //返回的数据
    private int code ;   //状态码

    private Admin admin ;
    private User user;

    private Result(String msg, int code){
        this.msg = msg ;
        this.code = code ;
    }

    private Result(String msg, int code, T t){
        this.msg = msg ;
        this.code = code ;
        this.data = t ;
    }

    private Result(Admin admin, int code, T t){
        this.admin = admin ;
        this.code = code ;
        this.data = t ;
    }
    private Result(User user, int code, T t){
        this.user = user ;
        this.code = code ;
        this.data = t ;
    }
    //对外提供几个static方法，创建该对象

    public static Result ok(){
        Result result = new Result("success",200) ;
        return  result ;
    }

    public static <T> Result<T> ok(T t){
        Result result = new Result("success",200,t) ;
        return  result ;
    }

    public static Result ok(String msg){
        Result result = new Result(msg,200) ;
        return  result ;
    }

    public static Result ok(String msg,int code){
        Result result = new Result(msg,code) ;
        return  result ;
    }

    //失败
    public static Result fail(){
        Result result = new Result("error",500) ;
        return  result ;
    }

    public static Result fail(String msg){
        Result result = new Result(msg,500) ;
        return  result ;
    }

    public static Result fail(String msg, int code) {
        Result result = new Result(msg,code) ;
        return  result ;
    }
}
